package com.mofeng.myshop.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.mofeng.myshop.domain.dto.search.CarmineQo;
import com.mofeng.myshop.domain.po.Carmine;
import org.apache.ibatis.annotations.*;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import java.util.Date;
import java.util.List;
import java.util.Set;

/**
 * 卡密 Mapper 接口
 *
 * @author 作者
 * @since 2024-11-10
 */
@Mapper
public interface CarmineMapper extends BaseMapper<Carmine> {


    @Select("SELECT * FROM `tb_carmine` WHERE `name` = #{name}")
    Carmine findByName(@Param("name") String name);

    @Select("SELECT * FROM `tb_carmine` WHERE `name` LIKE CONCAT('%',#{name},'%') ")
    List<Carmine> findLikeName(@Param("name") String name);


    @Select("SELECT * FROM `tb_carmine` WHERE `money` = #{money}")
    Set<Carmine> findByMoney(@Param("money") Integer money);

    @Select("SELECT * FROM `tb_carmine` WHERE `uuid` = #{uuid}")
    Set<Carmine> findByUuid(@Param("uuid") String uuid);

    @Select("SELECT * FROM `tb_carmine` WHERE `user_id` = #{userId}")
    Set<Carmine> findByUserId(@Param("userId") Long userId);

    @Select("SELECT * FROM `tb_carmine` WHERE `used` = #{used}")
    Set<Carmine> findByUsed(@Param("used") Integer used);

    @Select({"<script>",
            "SELECT * FROM `tb_carmine`",
            "<where>",
            "<if test='money != null'>",
            "AND `money` = #{money}",
            "</if>",

            "<if test='uuid != null'>",
            "AND `uuid` = #{uuid}",
            "</if>",

            "<if test='userId != null'>",
            "AND `user_id` = #{userId}",
            "</if>",

            "<if test='used != null'>",
            "AND `used` = #{used}",
            "</if>",

            "</where>",
            "</script>"})
    Set<Carmine> findBy(@Param("money") Integer money,
                        @Param("uuid") Integer uuid,
                        @Param("userId") Long userId,
                        @Param("used") Integer used
    );

    @Select({"<script>",
            "SELECT * FROM `tb_carmine`",
            "<where>",
            "<if test='money != null'>",
            "AND `money` = #{money}",
            "</if>",
            "<if test='uuid != null'>",
            "AND `uuid` = #{uuid}",
            "</if>",
            "<if test='userId != null'>",
            "AND `user_id` = #{userId}",
            "</if>",
            "<if test='used != null'>",
            "AND `used` = #{used}",
            "</if>",
            "</where>",
            "</script>"})
    Set<Carmine> findList(@Param("money") Integer money,
                          @Param("uuid") Integer uuid,
                          @Param("userId") Long userId,
                          @Param("used") Integer used);

    Page<Carmine> findPage(@Param("startTime") Date startTime,
                           @Param("endTime") Date endTime,
                           @Param("money") String money,
                           @Param("userId") Long userId,
                           @Param("used") Integer used, Page<Carmine> page);
}